 function Observer() {
     return function (target) {
         if (!target.prototype.hasOwnProperty('subscribers')) {
             Object.defineProperty(target.prototype, 'subscribers', {
                 value: {}
             })
         }
         if (!target.prototype.hasOwnProperty('addSubscriber')) {
             Object.defineProperty(target.prototype, "addSubscriber", {
                 value: function (key, fn) {
                     if (typeof fn !== 'function') {
                         console.warn("subscriber not a function");
                         return;
                     }

                     if (this.subscribers[key] === undefined) {
                         this.subscribers[key] = [];
                     }
                     this.subscribers[key].push(fn);
                 }
             });
         }
         if (!target.prototype.hasOwnProperty('removeSubscriber')) {
             Object.defineProperty(target.prototype, "removeSubscriber", {
                 value: function (key, fn) {
                     if (this.subscribers[key] === undefined) {
                         console.warn("subscriber not exists!");
                         return;
                     }
                     for (let i = 0, len = this.subscribers[key].length; i < len; i++) {
                         if (this.subscribers[key][i] === fn) {
                             this.subscribers[key].splice(i, 1);
                         }
                     }
                 }
             });
         }
         if (!target.prototype.hasOwnProperty('publish')) {
             Object.defineProperty(target.prototype, "publish", {
                 value: function (key, what) {
                     if (this.subscribers[key] === undefined) {
                         console.warn("subscriber not exists!");
                         return;
                     }

                     for (let i = 0, len = this.subscribers[key].length; i < len; i++) {
                         if (typeof this.subscribers[key][i] === 'function') {
                             this.subscribers[key][i](what);
                         }
                     }
                 }
             });
         }
     }
 }
 export {
     Observer
 }